/*
 * Internet.java
 * 
 * Created on 25.6.2007, 11:33:22
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package VidimAnetky;

//IO vyjimka a streamy
import java.io.IOException;
import java.io.*;

//HTTP spojeni a odeslani GET dotazu
import javax.microedition.io.HttpConnection;
import javax.microedition.io.Connector;

/**
 *
 * @author Kuba
 */

public class Internet {
    
    public static String httpGet(String url) throws IOException {
        HttpConnection connection = null;
        InputStream is = null;
        String response = null;
        try{
            connection = (HttpConnection)Connector.open(url);
            connection.setRequestMethod(HttpConnection.GET);
            /*otevreni streamu - odtedkajsem ONLINE
            na mobilu vyjede pravdepodobne potvrzeni pripojeni*/
            is = connection.openInputStream();
            //nacteni vracenych dat
            StringBuffer buf = new StringBuffer();
                int ch;
                while ((ch = is.read()) != -1) {
                    buf.append((char) ch);
                }
                response = buf.toString();
                return response;
        }
        finally{
            /*zavre se spojeni a stream
             IOException jsem vyhodil, pri vyjimce se tedy vrati prazdny string*/
            if(is != null) is.close();
            if(connection != null) connection.close();
        }
    }

}
